﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;



public partial class Admin_AdminHome : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["admin"] == null)
            {
                Response.Redirect("../Default.aspx");
            }
            else
            {
                if (1 == (int)Session["GroupID"])
                {
                    PublishSelectedButton.Visible = true;
                    PublishSelectedButton.Enabled = true;
                    UnpublishSelectedButton.Visible = true;
                    UnpublishSelectedButton.Enabled = true;
                    DeleteSelectedButton.Visible = true;
                    DeleteSelectedButton.Enabled = true;
                    New.Visible = true;
                    New.Enabled = true;
                }
                else if (2 == (int)Session["GroupID"])
                {
                    PublishSelectedButton.Visible = true;
                    PublishSelectedButton.Enabled = true;
                    UnpublishSelectedButton.Visible = true;
                    UnpublishSelectedButton.Enabled = true;
                }
                else if (0 == (int)Session["GroupID"])
                {
                    DeleteSelectedButton.Visible = true;
                    DeleteSelectedButton.Enabled = true;
                    New.Visible = true;
                    New.Enabled = true;
                }
                if (Session["InitType"] != null)
                {
                    switch (Session["InitType"].ToString())
                    {
                        case "3":
                            NoticeManage();
                            break;
                        case "2":
                            CollegeNewsManage();
                            break;
                        case "4":
                            IndependentInstituteDynamicManage();
                            break;
                        case "5":
                            CampusDynamicManage();
                            break;
                        case "1":
                            PictureNewsManage();
                            break;
                        case "9":
                            PostOnlineEdit();
                            break;
                        case "用户管理":
                            UserManage();
                            break;
                        case "相关链接管理":
                            RelativeLinksEdit();
                            break;
                        case "网页其他信息管理":
                            OtherInfoEdit();
                            break;
                        case "弹出网页管理":
                            PopUpPagesManage();
                            break;
                        case "搜索":
                            Search();
                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    PictureNewsManage();
                }
            }
        }
        else
        {
        }
    }

    // Invoke by others *NewsManagement_Click and *Manage function
    protected void NewsManagement(int catalogID)
    {
        NewsDataClassesDataContext dc = new NewsDataClassesDataContext();
        var Catalogs = from catalog in dc.Catalogs
                       where catalog.Catalog_id.Equals(catalogID)
                       select new
                       {
                           Catalog_id = catalog.Catalog_id,
                           Name = catalog.CatalogName
                       };
        foreach (var catalog in Catalogs)
        {
            Management.Text = catalog.Name+"管理";
        }
        SqlDataSource.SelectParameters["catalogID"].DefaultValue = catalogID.ToString();
        if (2==(int)Session["GroupID"])
        {
            SqlDataSource.SelectCommand = "SELECT News.News_id, News.Title, News.Time, News.isPublished, News.Editor, News.Checker, NewsToCatalog.Catalog_id FROM News INNER JOIN NewsToCatalog ON News.News_id = NewsToCatalog.News_id WHERE (NewsToCatalog.Catalog_id = @catalogID) ORDER BY News.Time DESC";
        }
    }



    public void PictureNewsManage()
    {
        NewsManagement(1);
    }
    public void CollegeNewsManage()
    {
        NewsManagement(2);
    }
    public void NoticeManage()
    {
        NewsManagement(3);
    }
    public void IndependentInstituteDynamicManage()
    {
        NewsManagement(4);
    }
    public void CampusDynamicManage()
    {
        NewsManagement(5);
    }

    public void UserManage()
    {
        Management.Text = "用户管理";
        if (1 == (int)Session["GroupID"])
        {
            SqlDataSource.SelectCommand = "SELECT User_id AS News_id, UserName AS Title, Group_id AS Time, Group_id AS isPublished,Group_id AS Catalog_id FROM UserInfo where Group_id=1 or Group_id=0 or Group_id=2";
            SqlDataSource.DeleteCommand = " ";
            PublishSelectedButton.Visible = false;
            PublishSelectedButton.Enabled = false;
            UnpublishSelectedButton.Visible = false;
            UnpublishSelectedButton.Enabled = false;
        }
        else
        {
            Response.Redirect("Admin/AdminHome.aspx");
        }
    }
   
    public void OtherInfoEdit()
    {
        Management.Text = "网页其他信息管理";
        if (1 == (int)Session["GroupID"])
        {
            SqlDataSource.SelectCommand = "SELECT OtherInfo_id as News_id,Title, OtherInfo_id AS Time, isPublished ,OtherInfo_id as Catalog_id FROM OtherInfo where OtherInfo_id=1 or OtherInfo_id=2";
            DeleteSelectedButton.Visible = false;
            New.Visible = false;
            PublishSelectedButton.Visible = false;
            UnpublishSelectedButton.Visible = false;
            SelectAllButton.Visible = false;
            SelectNoneButton.Visible = false;
            SelectOppositeButton.Visible = false;
 //           PublishSelectedButton.Text = "显示选中信息";
    //        UnpublishSelectedButton.Text = "不显示选中信息";
        }
        else
        {
            Response.Redirect("Admin/AdminHome.aspx");
        }
    }

    
    public void PopUpPagesManage()
    {
        Management.Text = "弹出网页管理";
        if (1 == (int)Session["GroupID"])
        {
            SqlDataSource.SelectCommand = "SELECT OtherInfo_id as News_id,Title, OtherInfo_id AS Time, isPublished ,OtherInfo_id as Catalog_id FROM OtherInfo where OtherInfo_id=3 or OtherInfo_id=4";
            DeleteSelectedButton.Visible = false;
            New.Visible = false;
            PublishSelectedButton.Visible = true;
            UnpublishSelectedButton.Visible = true;
            SelectAllButton.Visible = true;
            SelectNoneButton.Visible = true;
            SelectOppositeButton.Visible = true;
            PublishSelectedButton.Text = "允许弹出";
            UnpublishSelectedButton.Text = "不允许弹出";
        }
        else
        {
            Response.Redirect("Admin/AdminHome.aspx");
        }
    }

    public void RelativeLinksEdit()
    {
        Management.Text = "相关链接管理";
        if (1 == (int)Session["GroupID"])
        {
            SqlDataSource.SelectCommand = "SELECT LinksInfo_id as News_id,Title, LinksInfo_id AS Time, LinksInfo_id AS Catalog_id,isPublished FROM LinksInfo";
//            DeleteSelectedButton.Visible = false;
 //           New.Visible = false;
            PublishSelectedButton.Text = "显示选中信息";
            UnpublishSelectedButton.Text = "不显示选中信息";
            PublishSelectedButton.Visible = false;
            UnpublishSelectedButton.Visible = false;
        }
        else
        {
            Response.Redirect("Admin/AdminHome.aspx");
        }
    }

    public void PostOnlineEdit()
    {
        PublishSelectedButton.Visible = false;
        UnpublishSelectedButton.Visible = false;
        New.Visible = false;
        NewsManagement(9);
    }

    public void Search()
    {
        New.Visible = false;
        Management.Text = "搜索列表";
        Session.Add("Search", "false");
        if (0 == (int)Session["GroupID"])
        {
            if (Session["SearchCatalog"].ToString().Equals("0"))
            {
                string commandstring = "";
                commandstring += "SELECT News.News_id, News.Title, News.Time, NewsToCatalog.Catalog_id, News.isPublished, News.Editor, News.Checker, Catalog.CatalogName FROM News INNER JOIN NewsToCatalog ON News.News_id = NewsToCatalog.News_id INNER JOIN Catalog ON NewsToCatalog.Catalog_id = Catalog.Catalog_id WHERE (News.Title like '%";
                commandstring += Session["SearchKeyWord"].ToString().Trim();
                commandstring += "%') AND (News.Editor='";
                commandstring+= Session["UserID"].ToString();
                commandstring+="') ORDER BY News.News_id DESC";
                SqlDataSource.SelectCommand = commandstring;
            }
            else
            {
                string commandstring = "";
                commandstring += "SELECT News.News_id, News.Title, News.Time, NewsToCatalog.Catalog_id, News.isPublished, News.Editor, News.Checker, Catalog.CatalogName FROM News INNER JOIN NewsToCatalog ON News.News_id = NewsToCatalog.News_id INNER JOIN Catalog ON NewsToCatalog.Catalog_id = Catalog.Catalog_id WHERE (NewsToCatalog.Catalog_id=";
                commandstring += Session["SearchCatalog"].ToString();
                commandstring += ") AND (News.Title like '%";
                commandstring += Session["SearchKeyWord"].ToString().Trim();
                commandstring += "%') AND (News.Editor='";
                commandstring += Session["UserID"].ToString();
                commandstring += "') ORDER BY News.News_id DESC";
                SqlDataSource.SelectCommand = commandstring;
            }
        }
        else 
        {
            if (Session["SearchCatalog"].ToString().Equals("0"))
            {
                string commandstring = "";
                commandstring += "SELECT News.News_id, News.Title, News.Time, NewsToCatalog.Catalog_id, News.isPublished, News.Editor, News.Checker, Catalog.CatalogName FROM News INNER JOIN NewsToCatalog ON News.News_id = NewsToCatalog.News_id INNER JOIN Catalog ON NewsToCatalog.Catalog_id = Catalog.Catalog_id WHERE (News.Title like '%";
                commandstring += Session["SearchKeyWord"].ToString().Trim();
                commandstring += "%') ORDER BY News.News_id DESC";
                SqlDataSource.SelectCommand = commandstring;
            }
            else
            {
                string commandstring = "";
                commandstring += "SELECT News.News_id, News.Title, News.Time, NewsToCatalog.Catalog_id, News.isPublished, News.Editor, News.Checker, Catalog.CatalogName FROM News INNER JOIN NewsToCatalog ON News.News_id = NewsToCatalog.News_id INNER JOIN Catalog ON NewsToCatalog.Catalog_id = Catalog.Catalog_id WHERE (NewsToCatalog.Catalog_id=";
                commandstring += Session["SearchCatalog"].ToString();
                commandstring += ") AND (News.Title like '%";
                commandstring += Session["SearchKeyWord"].ToString().Trim();
                commandstring += "%') ORDER BY News.News_id DESC";
                SqlDataSource.SelectCommand = commandstring;
            }
        }
    }
    // Row Editing
    protected void NewsListGridView_RowEditing(object sender, GridViewEditEventArgs e)
    {
        Session.Add("OperationType", "Edit");
        Session.Add("News_id", ((Label)NewsListGridView.Rows[e.NewEditIndex].FindControl("News_id")).Text);
        Session.Add("List", Management.Text);
        Session.Add("NewsCatalogID", ((Label)NewsListGridView.Rows[e.NewEditIndex].FindControl("CatalogLabel")).Text);
        Session.Add("NewsType", Management.Text.Replace("列表", "编辑"));

        if ("1" == Session["InitType"].ToString() ||
            ("搜索" == Session["InitType"].ToString() &&
            ((Label)NewsListGridView.Rows[e.NewEditIndex].FindControl("CatalogLabel")).Text == "1"))
        {
            Response.Redirect("PictureNewsEdit.aspx");
        }
        else if (Management.Text.Equals("用户管理"))
        {
            Response.Redirect("UserEdit.aspx");
        }
        else if (Management.Text.Equals("网页其他信息管理"))
        {
            Response.Redirect("OtherInfoEdit.aspx");
        }
        else if (Management.Text.Equals("相关链接管理"))
        {
            Response.Redirect("RelativeLinkEdit.aspx");
        }
        else if (Management.Text.Equals("弹出网页管理"))
        {
            Response.Redirect("OtherInfoEdit.aspx");
        }
        else
        {
            Response.Redirect("CommonNewsEdit.aspx");
        }
    }

    protected void New_Button_Click(object sender, EventArgs e)
    {
        Session.Add("OperationType", "New");
        Session.Add("List", Management.Text);
        Session.Add("NewsCatalogID", Session["InitType"].ToString());
        Session.Add("NewsType", Management.Text.Replace("列表", "编辑"));

        if (Session["InitType"].ToString().Equals("1"))
        {
            Response.Redirect("PictureNewsEdit.aspx");
        }
        else if (Management.Text.Equals("用户管理"))
        {
            Response.Redirect("UserEdit.aspx");
        }
        else if (Management.Text.Equals("相关链接管理"))
        {
            Response.Redirect("RelativeLinkEdit.aspx");
        }
        else
        {
            Response.Redirect("CommonNewsEdit.aspx");
        }
    }
    protected void NewsListGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int news_id = Convert.ToInt32(((Label)NewsListGridView.Rows[e.RowIndex].FindControl("News_id")).Text);
 //       string news_CatalogID = ((Label)NewsListGridView.Rows[e.RowIndex].FindControl("CatalogLabel")).Text;
        try
        {
            if (Session["InitType"].ToString().Equals("1") ||
            ("搜索" == Session["InitType"].ToString() &&
            ((Label)NewsListGridView.Rows[e.RowIndex].FindControl("CatalogLabel")).Text == "1"))
            {
                NewsDataClassesDataContext dc = new NewsDataClassesDataContext();
                var delete_picture = from picture in dc.Pictures
                                     where picture.News_id.Equals(news_id)
                                     select picture;

                try
                {
                    dc.Pictures.DeleteAllOnSubmit(delete_picture);
                    dc.SubmitChanges();
                }
                catch (Exception ex)
                {
                }

                var delete_relation = from relation in dc.NewsToCatalogs
                                      where relation.News_id.Equals(news_id)
                                      select relation;
                try
                {
                    dc.NewsToCatalogs.DeleteAllOnSubmit(delete_relation);
                    dc.SubmitChanges();
                }
                catch (Exception ex)
                {
                }

                var delete_news = from news in dc.News
                                  where news.News_id.Equals(news_id)
                                  select news;
                try
                {
                    dc.News.DeleteAllOnSubmit(delete_news);
                    dc.SubmitChanges();
                }
                catch (Exception ex)
                {
                }
                dc.Dispose();

            }
            else if (Management.Text.Equals("用户管理"))
            {
                SQL.SQLHelper.DeleteUser(news_id);
            }
            else if (Management.Text.Equals("相关链接管理"))
            {
                NewsDataClassesDataContext dc = new NewsDataClassesDataContext();
                var delete_linksInfo = from linksInfo in dc.LinksInfos
                                     where linksInfo.LinksInfo_id.Equals(news_id)
                                     select linksInfo;

                try
                {
                    dc.LinksInfos.DeleteAllOnSubmit(delete_linksInfo);
                    dc.SubmitChanges();
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                SQL.SQLHelper.Delete(news_id);
            }
        }
        catch (Exception ex)
        {
        }

        switch (Session["InitType"].ToString())
        {
            case "3":
                NoticeManage();
                break;
            case "2":
                CollegeNewsManage();
                break;
            case "4":
                IndependentInstituteDynamicManage();
                break;
            case "5":
                CampusDynamicManage();
                break;
            case "1":
                PictureNewsManage();
                break;
            case "用户管理":
                UserManage();
                break;
            case "相关链接管理":
                RelativeLinksEdit();
                break;
            case "9":
                PostOnlineEdit();
                break;
            case "搜索":
                Search();
                break;
            default:
                CollegeNewsManage();
                break;
        }
    }

    protected void NewsListGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label News_title = e.Row.FindControl("News_title") as Label;
            News_title.Text = HtmlFormat.HtmlFormat.DeleteHtmlFormat(News_title.Text);
        }
        if (2 == (int)Session["GroupID"] && e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton Delete = e.Row.FindControl("Delete") as LinkButton;
            Delete.Visible = false;
        }
        if (Management.Text == "用户管理")
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label isPbulished = e.Row.FindControl("News_isPublished") as Label;
                isPbulished.Visible = false;
                Label News_Time = e.Row.FindControl("News_Time") as Label;
                if (News_Time != null)
                {
                    if (News_Time.Text == "1") News_Time.Text = "管理员";
                    else if (News_Time.Text == "0") News_Time.Text = "发稿用户";
                    else if (News_Time.Text == "2") News_Time.Text = "审稿用户";
                }
                Label News_id = e.Row.FindControl("News_id") as Label;
                if (News_id.Text == Session["UserID"]) e.Row.Visible = false;
            }
        }
        else if (Management.Text == "网页其他信息管理")
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label News_Time = e.Row.FindControl("News_Time") as Label;
                News_Time.Visible = false;
                LinkButton Delete = e.Row.FindControl("Delete") as LinkButton;
                Delete.Visible = false;
                Label isPbulished = e.Row.FindControl("News_isPublished") as Label;
                isPbulished.Visible = false;
//                 if (isPbulished != null)
//                 {
//                     if (isPbulished.Text == "已发布") isPbulished.Text = "显示";
//                     else isPbulished.Text = "未显示";
//                 }
                Label title = e.Row.FindControl("News_Title") as Label;
                title.Text ="页脚信息："+title.Text;
            }
        }
        else if (Management.Text == "弹出网页管理")
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label News_id = e.Row.FindControl("News_id") as Label;
                Label News_Time = e.Row.FindControl("News_Time") as Label;
                News_Time.Visible = false;
                LinkButton Delete = e.Row.FindControl("Delete") as LinkButton;
                Delete.Visible = false;
                Label isPbulished = e.Row.FindControl("News_isPublished") as Label;
                isPbulished.Visible = true;
                 if (isPbulished != null)
                {
                     if (isPbulished.Text == "已发布") isPbulished.Text = "允许弹出";
                    else isPbulished.Text = "不允许弹出";
                }
                Label title = e.Row.FindControl("News_Title") as Label;
                if(News_id.Text=="3")
                {
                    title.Text ="弹出网页一："+title.Text;
                }
                if(News_id.Text=="4")
                {
                    title.Text ="弹出网页二：" +title.Text;
                }
            }
        }
        else if (Management.Text == "相关链接管理")
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label News_Time = e.Row.FindControl("News_Time") as Label;
                News_Time.Visible = false;
                LinkButton Delete = e.Row.FindControl("Delete") as LinkButton;
                Delete.Visible = true;
                Label isPbulished = e.Row.FindControl("News_isPublished") as Label;
//                 if (isPbulished != null)
//                 {
//                     if (isPbulished.Text == "已发布") isPbulished.Text = "显示";
//                     else isPbulished.Text = "未显示";
//                 }
                isPbulished.Visible = false;
            }
        }
    }
    protected void PublishSelectedButton_Click(object sender, EventArgs e)
    {
        // Iterate through the Rows property
        bool changed=false;
        foreach (GridViewRow row in NewsListGridView.Rows)
        {
            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("NewsCheckBox");
            if (cb != null && cb.Checked)
            {
                // First, get the New ID for the selected row
                Label label = (Label)row.FindControl("News_id");
                int News_ID = 0;
                if (label!=null)
                {
                    News_ID=Convert.ToInt32(label.Text);
                }
                // Change the data to published
                NewsDataClassesDataContext dc = new NewsDataClassesDataContext();
                if (Management.Text == "网页其他信息管理")
                {
                    var News = from otherinfo in dc.OtherInfos
                               where otherinfo.OtherInfo_id.Equals(News_ID)
                               select otherinfo;
                    foreach (var otherinfo in News)
                    {
                        otherinfo.isPublished = 1;
                        changed = true;
                    }
                    dc.SubmitChanges();
                }
                if (Management.Text == "弹出网页管理")
                {
                    var News = from otherinfo in dc.OtherInfos
                               where otherinfo.OtherInfo_id.Equals(News_ID)
                               select otherinfo;
                    foreach (var otherinfo in News)
                    {
                        otherinfo.isPublished = 1;
                        changed = true;
                    }
                    dc.SubmitChanges();
                }
                else
                {
                    var News = from news in dc.News
                               where news.News_id.Equals(News_ID)
                               select news;
                    foreach (var news in News)
                    {
                        news.isPublished = 1;
                        changed = true;
                        if (news.Checker==0)
                        {
                            news.Checker = (int)Session["UserID"];
                        }
                    }
                    dc.SubmitChanges();
                }
                dc.Dispose();
            }
        }
        if (changed)
        {
            Response.Redirect("AdminHome.aspx");
        }
        // Show the Label if at least one row was deleted...
    }
    protected void UnpublishSelectedButton_Click(object sender, EventArgs e)
    {
        // Iterate through the Rows property
        bool changed = false;
        foreach (GridViewRow row in NewsListGridView.Rows)
        {
            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("NewsCheckBox");
            if (cb != null && cb.Checked)
            {
                // First, get the New ID for the selected row
                Label label = (Label)row.FindControl("News_id");
                int News_ID = 0;
                if (label != null)
                {
                    News_ID = Convert.ToInt32(label.Text);
                }

                // Change the data to published
                NewsDataClassesDataContext dc = new NewsDataClassesDataContext();
                if (Management.Text == "网页其他信息管理")
                {
                    var News = from otherinfo in dc.OtherInfos
                               where otherinfo.OtherInfo_id.Equals(News_ID)
                               select otherinfo;
                    foreach (var otherinfo in News)
                    {
                        otherinfo.isPublished = 0;
                        changed = true;
                    }
                    dc.SubmitChanges();
                }
                if (Management.Text == "弹出网页管理")
                {
                    var News = from otherinfo in dc.OtherInfos
                               where otherinfo.OtherInfo_id.Equals(News_ID)
                               select otherinfo;
                    foreach (var otherinfo in News)
                    {
                        otherinfo.isPublished = 0;
                        changed = true;
                    }
                    dc.SubmitChanges();
                }
                else
                {
                    var News = from news in dc.News
                               where news.News_id.Equals(News_ID)
                               select news;
                    foreach (var news in News)
                    {
                        changed = true;
                        news.isPublished = 0;
                    }
                    dc.SubmitChanges();
                }
               
                dc.Dispose();
            }
        }
        if (changed)
        {
            Response.Redirect("AdminHome.aspx");
        }
    }
    protected void DeleteSelectedButton_Click(object sender, EventArgs e)
    {
        bool changed = false;
        foreach (GridViewRow row in NewsListGridView.Rows)
        {
            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("NewsCheckBox");
            if (cb != null && cb.Checked)
            {
                // First, get the New ID for the selected row
                Label label = (Label)row.FindControl("News_id");
                int News_ID = 0;
                if (label != null)
                {
                    News_ID = Convert.ToInt32(label.Text);
                }

                // delete the data
                try
                {
                    if (Management.Text.Equals("相关链接管理"))
                    {
                        NewsDataClassesDataContext dc = new NewsDataClassesDataContext();
                        var LinksInfos = from linkinfo in dc.LinksInfos
                                             where linkinfo.LinksInfo_id.Equals(News_ID)
                                             select linkinfo;

                        try
                        {
                            dc.LinksInfos.DeleteAllOnSubmit(LinksInfos);
                            dc.SubmitChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    else if (Management.Text.Equals("图片新闻列表"))
                    {
                        NewsDataClassesDataContext dc = new NewsDataClassesDataContext();
                        var delete_picture = from picture in dc.Pictures
                                             where picture.News_id.Equals(News_ID)
                                             select picture;

                        try
                        {
                            dc.Pictures.DeleteAllOnSubmit(delete_picture);
                            dc.SubmitChanges();
                        }
                        catch (Exception ex)
                        {
                        }

                        var delete_relation = from relation in dc.NewsToCatalogs
                                              where relation.News_id.Equals(News_ID)
                                              select relation;
                        try
                        {
                            dc.NewsToCatalogs.DeleteAllOnSubmit(delete_relation);
                            dc.SubmitChanges();
                        }
                        catch (Exception ex)
                        {
                        }

                        var delete_news = from news in dc.News
                                          where news.News_id.Equals(News_ID)
                                          select news;
                        try
                        {
                            dc.News.DeleteAllOnSubmit(delete_news);
                            dc.SubmitChanges();
                        }
                        catch (Exception ex)
                        {
                        }
                        dc.Dispose();

                    }
                    else if (Management.Text.Equals("用户管理"))
                    {
                        SQL.SQLHelper.DeleteUser(News_ID);

                    }
                    else
                    {
                        SQL.SQLHelper.Delete(News_ID);
                    }
                }
                catch (Exception ex)
                {
                }
                changed=true;
            }
        }
        if (changed)
        {
            Response.Redirect("AdminHome.aspx");
        }
    }
    protected void SelectAllButton_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in NewsListGridView.Rows)
        {
            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("NewsCheckBox");
            if (cb != null)
                cb.Checked = true;
        }
    }
    protected void SelectNoneButton_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in NewsListGridView.Rows)
        {
            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("NewsCheckBox");
            if (cb != null)
                cb.Checked = false;
        }
    }
    protected void SelectOppositeButton_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in NewsListGridView.Rows)
        {
            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("NewsCheckBox");
            if (cb != null)
                cb.Checked = !cb.Checked;
        }
    }
}
